
<template>
    <div class="normal-container">
        <div v-if="!showDetail">
            <div class="normal-text">{{ $route.name }}</div>
            <div class="content-main">
                <section>
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="设备种类">
                            <el-select v-model="formInline.typeId" placeholder="请选择" clearable>
                                <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="设备名称">
                            <el-input v-model="formInline.name" placeholder="请输入设备名称" clearable></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" class="noraml-btn" @click="getList(true)">查询</el-button>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="noraml-btn" @click="Export"
                                v-loading.fullscreen.lock="fullscreenLoading">导出EXCEL</el-button>
                        </el-form-item>
                    </el-form>
                </section>
                <section>
                    <div
                        style="display: flex;justify-content: flex-end;font-size: 13px;margin-bottom: 10px;align-items: center;">
                        <div style="display: flex;align-items: center;">
                            <div
                                style="width: 11px;height: 11px;border: 1px solid #FF8E8E;background-color: #FFEEEE;margin-right: 5px;">
                            </div>
                            <div>
                                保养预警
                            </div>
                        </div>
                    </div>
                    <el-table v-loading="loading" :row-class-name="tableRowClassName" ref="tableMain" :header-cell-style="{
                        'text-align': 'center',
                        background: '#F6F7FB',
                        color: '#4B4B4B',
                        fontSize: '13px',
                    }" :cell-style="{ 'text-align': 'center' }" :data="tableData" style="width: 100%"
                        :max-height="tableHeight">
                        <el-table-column type="index" label="序号" width="50"></el-table-column>
                        <el-table-column prop="type" label="设备种类"></el-table-column>
                        <el-table-column prop="name" label="设备名称"></el-table-column>
                        <el-table-column prop="norm" label="设备型号"></el-table-column>
                        <el-table-column prop="factoryNo" label="出厂编号"></el-table-column>
                        <el-table-column prop="manufacturer" label="生产商"></el-table-column>
                        <el-table-column prop="spareParts" label="附属备件"></el-table-column>
                        <el-table-column prop="num" label="数量"></el-table-column>
                        <el-table-column prop="entryDate" label="入厂日期"></el-table-column>
                        <el-table-column prop="factoryId" label="厂内编号"></el-table-column>
                        <el-table-column prop="userDepar" label="使用部门"></el-table-column>
                        <el-table-column prop="life" label="使用年限"></el-table-column>
                        <el-table-column prop="serInter" label="保养周期"></el-table-column>
                        <el-table-column prop="" label="附件">
                            <template slot-scope="scope">
                                <img @click="showSerInter = true; id = scope.row.id" v-if="scope.row.sum"
                                    src="@/assets/icon/文件.png" style="cursor: pointer;" alt="">
                                <img v-else src="@/assets/icon/附件-灰色.png" style="cursor: not-allowed;" alt="">

                            </template>
                        </el-table-column>
                        <el-table-column prop="remark" label="备注"></el-table-column>
                        <el-table-column prop="status" label="状态" fixed="right" width="100">
                            <template slot-scope="scope">
                                <div class="is-useing" v-if="scope.row.status">在用</div>
                                <div class="is-no-seing" v-else>报废</div>
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" label="操作" width="130">
                            <template slot-scope="scope">
                                <el-tooltip content="详情" placement="top-start" effect="light">
                                    <img @click="clickDetail(false, scope.row)" src="@/assets/icon/列表icon-详情.png"
                                        style="margin-right: 10px;cursor: pointer;" alt="">
                                </el-tooltip>

                                <el-tooltip content="保养" placement="top-start" effect="light">
                                    <img @click="clickDetail(true, scope.row)" src="@/assets/icon/icon-保养.png"
                                        style="cursor: pointer;" alt="">
                                </el-tooltip>

                            </template>
                        </el-table-column>
                    </el-table>
                </section>
                <section style="text-align:center;padding-top:20px">
                    <el-pagination background @current-change="handleCurrentChange" :page-size="pageForm.size"
                        :current-page="pageForm.current" layout="prev, pager, next" :total="total">
                    </el-pagination>
                </section>
            </div>
        </div>
        <formItem v-if="showDetail" :name="'设备'" @closeformCollect="showDetail = false" :item="item" :firstEdit='edit'>
        </formItem>
        <serInterItem v-if="showSerInter" :genre="0" :showSerInter="showSerInter" :id="id"
            @closeSerInter="showSerInter = false; id = ''"></serInterItem>

    </div>
</template>
  
<script>
import serInterItem from '@/components/serInterDialog.vue'
import formItem from './components/formItem.vue'
export default {
    components: { formItem, serInterItem },

    data() {

        return {
            showSerInter: false,
            edit: false,
            item: {},
            messageDialog: false,
            options: [],
            showDetail: false,
            total: 0,
            loading: false,
            formInline: {
                typeId: '',
                name: '',
                genre: 0
            },
            pageForm: {
                current: 1,
                size: 20
            },
            tableData: [],
            id: "",
            tableHeight: 500,
            fullscreenLoading: false
        }
    },
    mounted() {
        this.getDept();
        this.getList();
        this.$nextTick(res => {
            const tableHeight = document.documentElement.clientHeight;
            const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 125;
            this.tableHeight = tableHeight - topHeight;
        })
    },
    computed: {
        listenHeight() {
            return this.$store.state.user.heightSize
        }
    },
    watch: {
        listenHeight(val) {
            if (!this.showDetail) {
                const tableHeight = document.documentElement.clientHeight;
                const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 125;
                this.tableHeight = tableHeight - topHeight;
            }

        }
    },
    methods: {
        Export() {
            this.fullscreenLoading = true;
            this.methExportExcel("post", "/mold/device/expInfo", this.formInline, "设备保养").then((res) => {
                this.fullscreenLoading = res;
            });

        },
        getDept() {
            this.$baseRequestGet("/sys/dict/getList/1", {}, "get").then(
                (res) => {
                    this.options = res.data;
                }
            ).catch(res => {
                this.loading = false;
            })
        },
        save() {
            this.messageDialog = false;
        },
        tableRowClassName({ row, rowIndex }) {
            if (row.alarm) {
                return 'warning-row';
            }
            return '';
        },
        clickDelete(item) {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        clickDetail(status, item) {
            this.item = item;
            this.edit = status;
            this.showDetail = true;
        },
        closeDetail(isFresh) {
            if (isFresh) this.getList();
            this.showDetail = false;
            this.id = '';
        },
        getList(isClear) {
            this.loading = true;
            if (isClear) this.pageForm.current = 1; // 点击搜索
            this.$baseRequest("/mold/device/serPageList", this.formInline, this.pageForm, "post").then(
                (res) => {
                    this.tableData = res.data.records;
                    this.total = Number(res.data.totalRow);
                    this.loading = false;
                }
            ).catch(res => {
                this.loading = false;
            })
        },
        handleCurrentChange(val) {
            this.pageForm.current = val;
            this.getList();
        },
    }
}
</script>
  
<style lang="scss" scoped>
.content-main {
    border: 1px solid #DFE2E8;
    padding: 30px;
    background-color: #fff;
}

.is-useing {
    color: #00B42A;
    position: relative;
}

.is-useing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #00B42A;
}

.is-no-seing {
    color: #FF7D00;
    position: relative;

}

.is-no-seing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #FF7D00;
}</style>
  